﻿using System;
using System.Net;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ComponentModel;
using System.Linq.Expressions;

namespace Fayshine.VA.Helpers
{
    public abstract class FilterDescription
    {
        protected FilterDescription() { }
        public abstract Expression ToExpression<T>(ParameterExpression param);
        public static FilterDescription Simple(string propertyPath, FilterOperation filterOperator, object value, bool isCaseSensitive)
        {
            return new SimpleFilterDescription()
            {
                PropertyPath = propertyPath,
                Operator = filterOperator,
                Value = value,
                IsCaseSensitive = isCaseSensitive
            };
        }
        public static FilterDescription Composite(LogicalOperation logicalOperator, FilterDescription left, FilterDescription right)
        {
            return new CompositeFilterDescription()
            {
                LogicalOperator = logicalOperator,
                Left = left,
                Right = right
            };
        }

    }
    public class SimpleFilterDescription : FilterDescription
    {
        public bool IsCaseSensitive
        {
            get;
            set;
        }

        public FilterOperation Operator
        {
            get;
            set;
        }
        public object Value
        {
            get;
            set;
        }
        public string PropertyPath
        {
            get;
            set;
        }
        public override Expression ToExpression<T>(ParameterExpression param)
        {
            return this.GetFilterExpression<T>(param);
        }
    }
    public interface IGetFilterDescription
    {
        SimpleFilterDescription GetFilterDescription();
    }
    public class CompositeFilterDescription : FilterDescription
    {
        public LogicalOperation LogicalOperator
        {
            get;
            set;
        }

        public FilterDescription Left
        {
            get;
            set;
        }
        public FilterDescription Right
        {
            get;
            set;
        }
        public override Expression ToExpression<T>(ParameterExpression param)
        {
            switch (LogicalOperator)
            {
                case LogicalOperation.Or:
                    return Expression.OrElse(Left.ToExpression<T>(param), Right.ToExpression<T>(param));
                default:
                    return Expression.AndAlso(Left.ToExpression<T>(param), Right.ToExpression<T>(param));

            }
        }

    }
}
